<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="srcPath" value="${redis:getSysConfig('sysFileVisitRoot_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript" src="${basePath}/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="${basePath}/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="${basePath}/ueditor/lang/zh-cn/zh-cn.js"></script>

<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm(){
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
             fields: {
                /* imageInfo_1: {
                    validators: {
                        notEmpty: {message: "请上传图片"},
                        file: {maxSize: 1024 * 1024, message: '请上传一张最大不超过1M的jpg/png/gif图片文件'}
                    }
                },  */
                title: {
                    validators: {
                        notEmpty: {message: "新闻标题不可为空"},
                        stringLength: {max: 50,message: "新闻标题最大长度为50"}
                    }
                },
                articleCode: {
                    validators: {
                        stringLength: {min: 2,max: 20,message: "新闻编码长度为2至20"},
                        regexp: {
                            regexp: /^[\w\s]+$/,
                            message: "编码不可用中文"
                        }
                    }
                },
            /*     brief: {
                    validators: {
                        notEmpty: {message: "摘要不可为空"},
                        stringLength: {max: 150,message: "摘要最大长度为150"}
                    }
                }, */
                content: {
                    validators: {
                        notEmpty: {message: "新闻详情不可为空"}
                    }
                },
                sortCode: {
                    validators: {
                        notEmpty: {message: "排序号不可为空"},
                        stringLength: {max: 10,message: "排序号最大长度为10"},
                        numeric: {
                            message: '排序号只能输入数字'
                        }
                    }
                }/* ,
                seoTitle: {
                    validators: {
                        notEmpty: {message: "SEO标题不可为空"},
                        stringLength: {max: 50,message: "SEO标题最大长度为50"}
                    }
                },
                keywords: {
                    validators: {
                        notEmpty: {message: "SEO关键字不可为空"},
                        stringLength: {max: 150,message: "SEO关键字最大长度为150"},
                        regexp: {
                            regexp: /^[\u4e00-\u9fa5]+$/,
                            message: "只能输入中文"
                        }
                    } 
                }*/
            }
        });
    }

    var editor;//初始化编辑器变量
    /**
     * 添加分类名称
     */
	<shiro:hasPermission name="back_gotoArticleList_add">
    function addInfo(){
        $("#myModalLabel").empty().text("添加新闻信息");
        /**清空隐藏域的值**/
        $("#articleId").val("");
        $("#imageUrl_1").val("");
        $("#showType").val("");
        $("#videoUrl").val("");
        $("#createTime").val("");
        $("#updateTime").val("");
        /**设置固定隐藏域的值  通过左侧的树节点点击展示右侧的子节点列表，则节点的id为列表的子节点的父id**/
        $("#categoryId").val($("#q_categoryId").val());
        /**清空编辑器中值**/
        editor.setContent("");
        /**清空表单控件中值**/
        resetAddForm();
        /**
         * 参数1 uploadIndex：页面文件的顺序位置  参数2 子系统目录  参数3 imageInfoPath：文件上传的存储目录
         * 参数4 maxFileCount：最多上传文件数量 参数5 maxImageWidth：上传图片的最大宽度 参数6 maxImageHeight：上传图片的最大高度
         */
        initImageForAdd(1,"sys_cms","image_article",1,120,120);
    }
	</shiro:hasPermission>

    /**
     * 编辑分类名称
     */
	<shiro:hasPermission name="back_gotoArticleList_update">
    function editInfo(){
		$("#myModalLabel").empty().text("修改新闻信息");
        /**获取选中行的id**/
        var selectedRow= $("#tt").bootstrapTable('getSelections');
        if(selectedRow.length==1){
            var id=selectedRow[0].articleId;
            $("#btn_edit").attr("data-target","#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/cmsArticle/getCmsArticle.sjson",
                data: {articleId:id},
                success: function(result){
                    var data = JSON.parse(result.data);
                    /**隐藏域**/
                    $("#articleId").val(data.articleId);
                    $("#categoryId").val(data.categoryId);
					$("#createTime").val(new Date(data.createTime).Format("yyyy-MM-dd hh:mm:ss"));
					$("#updateTime").val(new Date(data.updateTime).Format("yyyy-MM-dd hh:mm:ss"));
                    $("#imageUrl_1").val(data.imgUrl);
                    $("#showType").val(data.showType);
                    $("#videoUrl").val(data.videoUrl);
                    /**可见表单控件**/
                    $("#title").val(data.title);
                    $("#articleCode").val(data.articleCode);
                    $("#brief").val(data.brief);
                    $("#publishUser").val(data.publishUser);
                    $("#modifyUser").val(data.modifyUser);
                    $("#seoTitle").val(data.seoTitle);
                    $("#keywords").val(data.keywords);
                    $("#sortCode").val(data.sortCode);
                    $("#isShow_"+data.isShow).attr("checked",true);
                    editor.setContent(data.content);
                   /**回写预览上传文件所需的信息，如果有上传图片功能添加此代码，否则可以去掉**/
                    var fileName="";
                    if(data.imgUrl!=undefined) {
                        fileName = data.imgUrl.substring(data.imgUrl.lastIndexOf("/") + 1);
                    }
                    /**
                     * 参数1 uploadIndex：页面文件的顺序位置 参数2 子系统目录  参数3 imageInfoPath：文件上传的存储目录
                     * 参数4 maxFileCount：最多上传文件数量  参数5 maxImageWidth：上传图片的最大宽度 参数6 maxImageHeight：上传图片的最大高度
                     * 参数7 visitFileRoot：图片预览的访问根路径 参数8 fileSaveUrl：图片预览的访问相对路径 参数9 fileName：文件原始的名称
                     */
                    initImageForUpdate(1,"sys_cms","image_article",1,120,120,"${uploadPath}",data.imgUrl,fileName);
                    reValidateForm();
                    removeValidateField('imageInfo_1');
                }
            });
        }else{
            $("#btn_edit").attr("data-target","");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
    </shiro:hasPermission>

</script>

<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">
				<form id="form1"  method="post" action="${basePath}/back/cmsArticle/saveOrUpdateCmsArticle.sjson">
					<input id="categoryId" type="hidden"  name="categoryId" noclear="true" />
					<input id="articleId" type="hidden" name="articleId" />
					<input id="createTime" type="hidden" name="createTime" />
					<input id="updateTime" type="hidden" name="updateTime" />
					<input id="showType" type="hidden" name="showType" value=""/>
					<input id="videoUrl" type="hidden" name="videoUrl" value=""/>

					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">

						<tr>
							<td class="toright_td" width="150px"><!-- <span style="color:red">* </span> -->主题图片:</td>
							<td class="toleft_td" colspan="3">
								<div class="container">
									<input id="imageUrl_1" type="hidden" name="imgUrl" value=""/>
									<div class="form-group" id="fileWrap1"></div>
								</div>
								<span style="color:red">提示：请上传规格宽120px，高120px的图片</span>
							</td>
						</tr>

						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span> 新闻标题:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input id="title" class="form-control input-sm" type="text" name="title" placeholder="请输入新闻标题"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"> 新闻编码:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<input id="articleCode" class="form-control input-sm" type="text" name="articleCode" placeholder="请输入新闻编码"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><!-- <span style="color:red">* </span> -->摘要:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<textarea id="brief" class="form-control input-sm" type="text" name="brief" placeholder="请输入摘要"></textarea>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span> 新闻详情:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<div class="form-group">
									<!--百度ueditor编辑器-->
									<textarea id="content" name="content" style="width:100%;height:200px;font-size:12px;"></textarea>
									<script type="text/javascript">
                                        editor = UE.getEditor('content');
                                        UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
                                        UE.Editor.prototype.getActionUrl = function(action) {
                                            if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
                                                return '${basePath}/back/upload/imgUploadByUeditor.sjson?subSysFolderName=ueFile_cms&imageInfoPath=image_ueditor';
                                            }  else {
                                                return this._bkGetActionUrl.call(this, action);
                                            }
                                        }
									</script>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span> 排序号:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="sortCode" name="sortCode" placeholder="请输入排序号"/>
								</div>
							</td>
							<td class="toright_td" width="150px">是否显示 :&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<label class="checkbox-inline">
									<input type="radio" name="isShow" id="isShow_1" class="radioInput" value="1">&nbsp;已显示
								</label>
								<label class="checkbox-inline">
									<input type="radio" name="isShow" id="isShow_0" class="radioInput" value="0"  checked>&nbsp;未显示
								</label>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><!-- <span style="color:red">* </span> -->SEO标题:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input id="seoTitle" class="form-control input-sm" type="text" name="seoTitle" placeholder="请输入SEO标题"/>
								</div>
							</td>
							<td class="toright_td" width="150px"><!-- <span style="color:red">* </span> -->SEO关键词:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input id="keywords" class="form-control input-sm" type="text" name="keywords" placeholder="请输入SEO关键词"/>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
